void init_dict(int dict[]) {
    dict['I' - 'A'] = 1;
    dict['V' - 'A'] = 5;
    dict['X' - 'A'] = 10;
    dict['L' - 'A'] = 50;
    dict['C' - 'A'] = 100;
    dict['D' - 'A'] = 500;
    dict['M' - 'A'] = 1000;
}

int romanToInt(char * s){
    int len = strlen(s);
    int dict[26] = {0};    //大写字母
    init_dict(dict);

    int sum = 0;
    for (int i = 0; i < len; i++) {
        sum += dict[s[i] - 'A'];
    }

    for (int i = 0; i < len - 1; i++) {
        if (s[i] == 'I' && (s[i+1] == 'V' || s[i+1] == 'X')) sum -= dict[s[i] - 'A'] * 2;
        else if (s[i] == 'X' && (s[i+1] == 'L' || s[i+1] == 'C')) sum -= dict[s[i] - 'A'] * 2;
        else if (s[i] == 'C' && (s[i+1] == 'D' || s[i+1] == 'M')) sum -= dict[s[i] - 'A'] * 2;
        else ;
    }
    return sum;
}

// 也可以转换成switch - case方式